﻿using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.Weaning.ApI.Application.Command;
using static S.Weaning.ApI.Application.Command.MaternalWeaningCommand;

namespace S.Weaning.ApI.Controllers
{
    /// <summary>
    /// 种母断奶写
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WeaningController : BaseController
    {
        private readonly IMediator mediator;
        public WeaningController(IMediator mediator,MySqlDbContext _db) : base(_db)
        {
            this.mediator = mediator;
        }
        /// <summary>
        ///种母断奶新增
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult>  AddMaternalWeaning(AddMaternalMatingCommand command)
        {
            foreach (var item in command.maternalWarnings)
            {
                item.CreateBy = UserStrategyDto.UserTrueName;
            }
            return Ok(await mediator.Send(command));
        }
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> UpdExamine(string id)
        {
            var command = new UpdExamineCommand(id);
            var result = await mediator.Send(command);
            return Ok(result); // 返回修改的记录数或其他相关信息
        }
       /// <summary>
       /// 删除断奶信息
       /// </summary>
       /// <param name="id"></param>
       /// <returns></returns>
        [HttpDelete]
        public async Task<IActionResult> DelMaternal(string id)
        {
            var command = new DelMaternalCommand(id);
            var result = await mediator.Send(command);
            return Ok(result); // 返回修改的记录数或其他相关信息
        }
        /// <summary>
        ///种母断奶修改
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdMaternalWeaning(UpdMaternalCommand command)
        {
            command.UpdateBy = UserStrategyDto.UserTrueName;
            return Ok(await mediator.Send(command));
        }
    }
}
